home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / REFERENC / TPR / TPR4B.TXT < prev    next >
Text File  |  1992-10-19  |  78KB  |  2,183 lines

  1.                    Chapter 4
  2.                  - continued -
  3.                  - Part 2 of 2 parts -
  4.                                     of the
  5.                             Turbo Pascal Reference
  6.  
  7.               The System Library Reference
  8.  
  9.  
  10. This chapter is part of the Turbo Pascal Reference electronic freeware book (C)
  11. Copyright 1992 by Ed Mitchell.  This freeware book contains supplementary
  12. material to Borland Pascal Developer's Guide, published by Que Corporation,
  13. 1992.  However, Que Corporation has no affiliation with nor responsibility for
  14. the content of this free book.  Please see Chapter 1 of the Turbo Pascal
  15. Reference for important information about your right to distribute and use this
  16. material freely.  If you find this material of use, I would appreciate your
  17. purchase of one my books, such as the Borland Pascal Developer's Guide or
  18. Secrets of the Borland C++ Masters, Sams Books, 1992.  Thank you.
  19.  
  20.  
  21. IOResult function
  22. ----------------------------------------------------------------
  23. Declaration:  
  24.      function IOResult : Word;
  25.  
  26. Example:
  27.      repeat
  28.        Writeln( 'Enter name of file to open:' );
  29.        Readln( FileName );
  30.        {$I-}
  31.        Assign( F, FileName );
  32.        Reset( F );
  33.        {$I+} { I usually leave $I- set for the duration of my
  34.               programs }
  35.        ErrorCode := IOResult;
  36.        if ErrorCode <> 0   then
  37.        begin
  38.           Writeln('Unable to open file ', FileName );
  39.        end;
  40.      until  ErrorCode = 0;
  41.  
  42. Purpose:
  43.      IOResult returns the error code of the last input/output operation.  To
  44. use IOResult, you must disable automatic IOResult checking by writing {$I-}
  45. before performing an I/O operation.  Then, after each I/O operation you can
  46. manually check the result code returned by IOResult, and take appropriate
  47. action.
  48.      Normally, you should copy the value of IOResult to a temporary variable,
  49. like this:
  50.  
  51.      ErrorCode := IOResult;
  52.      If ErrorCode <> 0 then {take action}
  53.  
  54. While you can check IOResult directly, IOResult resets the last error condition
  55. to zero when called.  This means if you check the value of  IOResult in an
  56. if-then statement, and then in the process of handling the error you again
  57. reference IOResult, the value returned will now be 0! Trying to track this type
  58. of problem is a bit maddening until you realize that IOResult returns the
  59. current error code and then resets itself to zero.
  60.  
  61.  
  62.  
  63. Keep procedure
  64. ----------------------------------------------------------------
  65. Declaration:  
  66.      procedure Keep(ExitCode: Word);
  67.  
  68. Unit:       Dos
  69.  
  70. Purpose:
  71.      Terminates a program but leaves the program resident in memory.  Such a
  72. program is a TSR program, which must latch itself onto a interrupt to be
  73. "revivied", and which must  be aware of the other considerations that apply to
  74. a TSR program (such as avoiding DOS reentrant code and so on).  The ExitCode
  75. parameter value is passed to the Halt standard procedure for indicating an
  76. error condition.  DO NOT use this procedure unless you know what you are doing!
  77.  You can learn how to write a TSR program entirely in Turbo Pascal by reading
  78. Chapter 9, "Special Programming Techniques:  8087 Usage, Interrupts and TSRs",
  79. in the Borland Pascal Developer's Guide, from Que Books.
  80.  
  81.  
  82.  
  83. KeyPressed function
  84. ----------------------------------------------------------------
  85. Declaration:  
  86.      function KeyPressed : Boolean;
  87.  
  88. Unit:       Crt
  89.  
  90. Example:
  91.  
  92.      repeat
  93.        { Do any operations repeatedly here }
  94.      until KeyPressed;
  95.  
  96. Purpose:
  97.      KeyPressed returns True if a keyboard character has been typed, False
  98. otherwise.  KeyPressed is useful for executing a section of code until a
  99. character is typed at the keyboard.  KeyPressed only tells you that 1 or more
  100. characters have been typed; you need to call Read, Readln or ReadKey to read
  101. the input.
  102. See ReadKey
  103.  
  104.  
  105.  
  106. Length function
  107. ----------------------------------------------------------------
  108. Declaration:  
  109.      function Length ( S : String );
  110.  
  111. Example:
  112.  
  113.      Writeln( Length ('ABCDEFGHIJKLMNOPQRSTUVWXYZ') );
  114.  
  115. outputs,
  116.  
  117.      26
  118.  
  119. Purpose:
  120.      Length(S) returns the current value of the length byte of S, which is the
  121. actual length of the string that is stored in S.  SizeOf returns the total
  122. storage occupied by S.  If, for example, S is declared as,
  123.      var
  124.        S : String[80];
  125. then SizeOf(S) returns 81 (80 bytes plus the length byte), and Length(S)
  126. returns a value from 0 to 80, depending upon the current contents of the
  127. string.
  128. See SizeOf
  129.  
  130.  
  131.  
  132. Ln function
  133. ----------------------------------------------------------------
  134. Declaration:  
  135.      function Ln( X : Real );
  136.  
  137. Purpose:
  138.      Returns the natural logarithm of X.  To compute the base 10 logarithm of
  139. an expression, define a new function like this:
  140.      function Log10 ( X : Real ): Real;
  141.      begin
  142.        Log10 := Ln(X) / Ln(10);
  143.      end;
  144. See Exp
  145.  
  146.  
  147. Lo function
  148. ----------------------------------------------------------------
  149. Declaration:  
  150.      function Lo(X): Byte;
  151.  
  152. Purpose:
  153.      Returns the low byte of X, where X is either an Integer or Word value. 
  154. Thefunction Hi(X) returns the corresponding high byte.
  155. See Hi, Swap
  156.  
  157.  
  158.  
  159. LowVideo procedure
  160. ----------------------------------------------------------------
  161. Declaration:  
  162.      procedure LowVideo;
  163.  
  164. Unit:       Crt
  165.  
  166. Purpose:
  167.      Performs the inverse of HighVideo by subtracting 8 from the text
  168. attribute's foreground color, translating color values in the range 8 to 15
  169. down to 0 to 7.  See HighVideo for more details.
  170. See HighVideo, NormVideo, TextColor
  171.  
  172.  
  173.  
  174. Lst file
  175. ----------------------------------------------------------------
  176. Declaration:  
  177.      Lst : Text;
  178.  
  179. Unit:       Printer
  180.  
  181. Purpose:
  182.      The Printer unit provides a special Lst file identifier for easy printer
  183. output.  All you need do to use Lst, is use the Printer unit in your program or
  184. unit's uses statement.  Thereafter, to send output to the printer, specify Lst
  185. as the file identifier in your Write or Writeln statements.  You do not need to
  186. open or close the printer as this is handled automatically by the Printer
  187. unit's internal initialization section.
  188. See Write, Writeln
  189.  
  190.  
  191.  
  192. Mark procedure
  193. ----------------------------------------------------------------
  194. Declaration:  
  195.      procedure Mark (var P: Pointer);
  196.  
  197. Purpose:
  198.      Copies the current value of the heap pointer to P.  Mark, together with
  199. Release, enable you to dynamically allocate a group of objects, and then
  200. dispose of them in a single call to Release.  See "The Use of Mark and Release
  201. Procedures" in Chapter 3, for full details.
  202.  
  203.  
  204.  
  205. MaxAvail function
  206. ----------------------------------------------------------------
  207. Declaration:  
  208.      function MaxAvail : Longint;
  209.  
  210. Purpose:
  211.      During program execution, the heap memory area may become fragmented with
  212. blocks allocated here and there.  By calling MaxAvail you can determine the
  213. size, in bytes, of the largest free block available for allocation.  A related
  214. function, MemAvail, returns the total number of free bytes available in the
  215. heap.
  216.  
  217.  
  218.  
  219. MemAvail function
  220. ----------------------------------------------------------------
  221. Declaration:  
  222.      function MemAvail : Longint;
  223.  
  224. Purpose:
  225.      Returns the total number of free bytes in the heap.  Note that you may not
  226. be able to allocate a dynamic variable as large as MemAvail because the heap
  227. may be fragmented.  You can determine the largest possible free block by
  228. calling MaxAvail.
  229.      A common use for MemAvail is to periodically check your memory allocation
  230. and deallocation.  If you find that MemAvail is constantly increasing durng
  231. program execution, you may be dynamically allocating a variable and never
  232. disposing of the memory block.  Eventually, your program will run out of memory
  233. and be halted.
  234.      You may also wish to place MemAvail checks at key points within your
  235. program.  For example, before calling a procedure that makes a large number of
  236. dynamic memory allocations, save the contents of MemAvail in another variable. 
  237. Then, upon return from the procedure, compare MemAvail to the saved value.  If
  238. they are not the same, this is a sign that somewhere within the called
  239. procedure, or perhaps a procedure called by it, memory is not being properly
  240. disposed.
  241.  
  242.  
  243.  
  244. Mkdir procedure
  245. ----------------------------------------------------------------
  246. Declaration:  
  247.      procedure MkDir(S: String);
  248.  
  249. Example:  
  250. var
  251.      DirName : String;
  252.      ErrorCode : Integer;
  253. begin
  254.      repeat
  255.        Write('Enter name of directory to make: ');
  256.        Readln( DirName );
  257.        if  DirName <> ''  then
  258.        begin
  259.           {$I-}
  260.           MkDir ( DirName );
  261.           ErrorCode := IOResult;
  262.           if ErrorCode <> 0 then
  263.             Writeln('Error creating directory ', DirName )
  264.           else
  265.             Writeln('Directory ', DirName, 
  266.               ' has been created.');
  267.        end;
  268.      until DirName = '';
  269. end.
  270.  
  271. Purpose:
  272.      To create or make a subdirectory, call MkDir, setting the parameter S to
  273. the name of the directory to create.  S may specify a full path, such as
  274. 'C:\TP\UTILS\GRAPHICS' or a simple directory name such as 'GRAPHICS' which
  275. creates subdirectory 'GRAPHICS' in the current subdirectory.  
  276.      The directory name specified may not be the name of an existing file.  You
  277. can check for errors by setting {$I-} and examining the value returned by
  278. IOResult.
  279.  
  280.  
  281.  
  282. Move procedure
  283. ----------------------------------------------------------------
  284. Declaration:  
  285.      procedure Move (var Source, Dest; Count : Word);
  286.  
  287. Example:
  288.    1  { DEMOMOVE.PAS }
  289.    2  program MoveDemo;
  290.    3  { Demonstrates how Move procedure can be used to move large numbers
  291.    4  of bytes around inside an array.  This demo stores lines of text
  292.    5  into a large TextArray.  New lines are added by calling AddLine, which
  293.    6  calls MakeAHole to slide the existing data in the TextArray to make
  294.    7  room for new text.  AddLine then uses Move to copy the string data
  295.    8  into TextArray.  Data is fetched using the procedure GetLine.
  296.    9    The variable CurSize keeps track of how many bytes of TextArray are
  297.   10  currently in use.  CurLocation keeps track of the current position; if we
  298.   11  were writing a text editor based on this approach, CurLocation would
  299. index
  300.   12  into TextArray where the editor's cursor appears on the screen.  In other
  301.   13  word, the next new line that we type would be inserted at CurLocation.
  302.   14  }
  303.   15  
  304.   16  const
  305.   17    MaxSize = 32000;
  306.   18    MARKER = 13;
  307.   19  
  308.   20  var
  309.   21    TextArray : Array[0..MaxSize] of Char;
  310.   22    CurSize : Word;
  311.   23    CurLocation : Word;
  312.   24  
  313.   25  
  314.   26  procedure MakeAHole ( Address : Word; Size : Word );
  315.   27  { Slides data in the TextArray sideways, leaving a "hole" to fill
  316.   28  with new data }
  317.   29  begin
  318.   30    Move( TextArray[Address], TextArray[Address+Size], CurSize - Address +
  319. 1 );
  320.   31  end;
  321.   32  
  322.   33  
  323.   34  
  324.   35  procedure AddLine ( var Address : Word; S : String );
  325.   36  { Adds the contents of S to the TextArray, starting at location Address }
  326.   37  var
  327.   38    NumBytes : Integer;
  328.   39  begin
  329.   40    NumBytes := Length(S) + 1;
  330.   41    S[0] := Chr(MARKER);
  331.   42    MakeAHole ( Address, NumBytes );
  332.   43    Move( S[0], TextArray[Address], NumBytes );
  333.   44    CurSize := CurSize + NumBytes;
  334.   45    Address := Address + NumBytes;
  335.   46  end;
  336.   47  
  337.   48  
  338.   49  
  339.   50  procedure GetLine ( Address : Word; var S : String );
  340.   51  { On entry, Address points to a MARKER character in the text array. 
  341. GetLine
  342.   52  copies the text between this marker and the next marker (or end of array)
  343.   53  to S. }
  344.   54  var
  345.   55    TempAddr : Word;
  346.   56  begin
  347.   57    TempAddr := Address + 1;
  348.   58    while (TempAddr <= CurSize) and
  349.   59          (TextArray[TempAddr] <> Chr(MARKER)) do
  350.   60      Inc(TempAddr);
  351.   61    Move ( TextArray[Address+1], S[1], TempAddr - Address );
  352.   62    S[0] := chr( TempAddr - Address );
  353.   63  end;
  354.   64  
  355.   65  
  356.   66  procedure MoveAhead (var Address : Word );
  357.   67  { Where address points to some location in TextArray, MoveAhead positions
  358.   68  Address to the index location of the next Marker character. }
  359.   69  begin
  360.   70    if  TextArray[Address] = chr(MARKER)  then
  361.   71      Inc(Address);
  362.   72    while (Address <= CurSize) and
  363.   73          (TextArray[Address] <> Chr(MARKER)) do
  364.   74      Inc(Address);
  365.   75  end;
  366.   76  
  367.   77  
  368.   78  var
  369.   79    I : Integer;
  370.   80    ALine : String;
  371.   81  
  372.   82  begin
  373.   83    CurSize := 0;
  374.   84    CurLocation := 0;
  375.   85  
  376.   86    { Add some sample data into TextArray }
  377.   87    AddLine ( CurLocation, 'Line 1 I''m the first line of data');
  378.   88    AddLine ( CurLocation, 'Line 2 and I''m the second!');
  379.   89    AddLine ( CurLocation, 'Line 3 The quick brown fox jumped over the');
  380.   90    AddLine ( CurLocation, 'Line 4 lazy brown dog and fell and hurt
  381. herself.');
  382.   91  
  383.   92    CurLocation := 0;
  384.   93    MoveAhead ( CurLocation );
  385.   94    AddLine ( CurLocation, 'One more line!!!!!');
  386.   95  
  387.   96    CurLocation := 0;
  388.   97    for I := 1 to 5 do
  389.   98    begin
  390.   99      GetLine ( CurLocation, ALine );
  391.  100      Writeln( ALine );
  392.  101      MoveAhead ( CurLocation );
  393.  102    end;
  394.  103  
  395.  104    readln;
  396.  105  end.
  397.  
  398. Purpose:
  399.      Move copies a block of bytes of Count size from Source to Dest.  Move uses
  400. optimized assembly language to provide extremely fast copies of potentially
  401. large amounts of data and is particular useful for sliding values around inside
  402. large text arrays, such as might be used in a text editor (see example, above).
  403.  
  404. Important! Range Checking!
  405.      Move does not perform range checking.  You may, for instance, move 30,000
  406. bytes into a 255 character string.  And Move will go ahead and do just that,
  407. writing over portions of your run-time stack, other variables, and generally
  408. anything else that gets in the way.  So be careful!
  409.  
  410.  
  411.  
  412. MsDos procedure
  413. ----------------------------------------------------------------
  414. Declaration:  
  415.      procedure MsDos (var Regs: Registers );
  416.  
  417. Unit:       Dos
  418.  
  419. Example:
  420.      uses
  421.        Dos;
  422.      var
  423.        Reg : Registers;
  424.      begin
  425.        { Call the DOS Int 21H Function 0EH Select Disk function
  426.        to determine
  427.        the maximum number of drives permitted for the system;
  428.        this
  429.        is equivalent to the number of logical drives on the
  430.        system, or
  431.        the LASTDRIVE value in the CONFIG.SYS file, or a default
  432.        of 5
  433.        if LASTDRIVE (approximately) }
  434.        Reg.AH := $0E;
  435.        Reg.DL := $00;
  436.        MsDos( Reg );
  437.        Writeln( 'Total Drives=', Reg.AL );
  438.      end.
  439.  
  440. Purpose:
  441.      MsDos access the DOS-functions available through software interrupt 21H. 
  442. While most of the especially useful DOS-level functions are available through
  443. Turbo Pascal library routines such as GetFTime, SetDate, and so on, you can
  444. access some of the other functions using the MsDos procedure call mechanism. 
  445. The variable parameter Regs defines a case variant record structure for
  446. representing the CPU registers, where Register is defined as:
  447.  
  448. type
  449.      Registers = record
  450.        case Integer of
  451.           0: (AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags: Word);
  452.           1: (Al, AH, BL, BH, CL, CH, DL, DH: Byte);
  453.      end;
  454.  
  455. Note that the SS and SP registers are not available in this structure and
  456. cannot be used in conjunction with MsDos calls.  For complete details on DOS
  457. function calls, see DOS Programmer's Reference, by Terry Dettmann and Jim Kyle
  458. (Que Books, 1989).
  459.  
  460.  
  461.  
  462. New procedure
  463. ----------------------------------------------------------------
  464. Declaration:  
  465.      procedure New( var P: Pointer [, Init: constructor ] );
  466.  
  467. Example:
  468.      See "The Pointer type" in Chapter 3 of the Turbo Pascal Reference.
  469.  
  470. Purpose:
  471.      Dynamic variable allocations and dynamic object creations are performed
  472. with New.  New allocates a memory block, from the heap memory area, and sets P
  473. to point to the memory block.  If P points to an object, you can optionally add
  474. the name of the object's constructor method and it will be called immediately
  475. after the memory is allocated.  This provides a short hand method of
  476. simultaneously allocating and initializing the object's fields and virtual
  477. method table.
  478.      The New procedure may fail if there is insufficient memory in the heap to
  479. allocate the new block.  Normally, this results in a run-time error that
  480. terminates the program.  However, by setting the HeapError variable to point to
  481. your own heap error handler, your program can take steps to gracefully recover
  482. from out of memory conditions.  See HeapError in this section, and chapter 3,
  483. "Pointers and Memory Management" for tips on trapping the out of memory error
  484. condition.
  485.      You must make certain that you dispose of allocated memory blocks once
  486. they are no longer needed (see Dispose).  If you fail to dispose of a memory
  487. block it continues to occupy memory space and can contribute to your program's
  488. running of out memory.
  489.      Since a pointer variable "points" to a memory block, you reference the
  490. thing that P points to by typing P^.  This is described in chapter 3.  
  491. See Dispose, FreeMem, GetMem
  492.  
  493.  
  494.  
  495. NormVideo procedure
  496. ----------------------------------------------------------------
  497. Declaration:  
  498.      procedure NormVideo;
  499.  
  500. Unit:       Crt
  501.  
  502. Purpose:
  503.      Resets the current text attribute to the original text attribute that was
  504. in use when the program was launched.  Specifically, when the program is
  505. started, the value of the text attribute where the cursor is located is saved. 
  506. You can use NormVideo to restore this original text attribute at program exit. 
  507. By doing so, the screen image will be reset to whatever screen attributes were
  508. in effect when the program was started (or specifically, the screen attribute
  509. at the cursor's location when the program was started).
  510. See HighVideo, LowVideo, TextBackground, Textcolor
  511.  
  512.  
  513.  
  514. NoSound procedure
  515. ----------------------------------------------------------------
  516. Declaration:  
  517.      procedure NoSound;
  518.  
  519. Unit:       Crt
  520.  
  521. Purpose:
  522.      NoSound is used in conjunction with the Sound procedure.  Sound turns on
  523. the speaker and emits a user selected tone.  To turn off the speaker, call
  524. NoSound.
  525. See Sound
  526.  
  527.  
  528.  
  529. Odd function
  530. ----------------------------------------------------------------
  531. Declaration:  
  532.      function Odd( X: Longint ): Boolean;
  533.  
  534. Purpose:
  535.      Odd returns True if its parameter is an odd number, or False if its
  536. parameter is an even number.  Sort of an odd function.
  537.  
  538.  
  539.  
  540. Ofs function
  541. ----------------------------------------------------------------
  542. Declaration:  
  543.      function Ofs( X ): Word;
  544.  
  545. Purpose:
  546.      Where X is any type of variable, Ofs(X) produces the offset portion of the
  547. variable's address.  All 80x86 addresses consist of a segment:offset word pair.
  548. The two values are added together to produce the actual physical memory
  549. address.  To find the corresponding segment value, call Seg(X).
  550. See Addr, Seg
  551.  
  552.  
  553.  
  554. Ord function
  555. ----------------------------------------------------------------
  556. Declaration:  
  557.      function Ord( X ): Longint;
  558.  
  559. Example:
  560.      var
  561.        I : Integer;
  562.        S : String;
  563.      ...
  564.      { Convert all upper case letters to lower case letters }
  565.      for I := 1 to Length(S) do
  566.        if (S[I]>='A') and (S[I]<='Z')  then
  567.           S[I] := Chr( Ord(S[I]) + 32 );
  568.  
  569. Purpose:
  570.      Ord translates its parameter X to a Longint value reprsenting X's
  571. ordinality.  For example, Ord('A') returns a value of 65, because A is the
  572. sixty-fifth value in the set of characters (this also coincides with 'A's ASCII
  573. code value).  The sample code shown above uses Ord to convert a character value
  574. to its ASCII code.  Since the capital letter 'A' has an ASCII value of 65, and
  575. the lower case letter 'A' has an ASCII code of 97, adding 32 to the ordinal
  576. value of a character is equivlant to converting the character to lower case. 
  577. Chr converts the integer result back to a character value.
  578. If you have an ordinal type declared as,
  579.      type
  580.        DaysOfTheWeek= (Sun,Mon,Tue,Wed,Thu,Fri,Sat);
  581.      var
  582.        Day : DaysOfTheWeek;
  583.  
  584. And then the code, 
  585.  
  586.      Day := Tue;
  587.      Writeln(Ord(Day));
  588.  
  589. The output will be:
  590.      2
  591. since the ordinal values of DaysOfTheWeek are:
  592.      Sun  0
  593.      Mon  1
  594.      Tue  2
  595.      Wed  3
  596.      Thu  4
  597.      Fri    5
  598.      Sat    6
  599.  
  600.  
  601.  
  602. PackTime procedure
  603. ----------------------------------------------------------------
  604. Declaration:  
  605.      procedure PackTime(var DT: DateTime; var Time: Longint);
  606.  
  607. Unit:       Dos
  608.  
  609. Example:
  610.      uses dos;
  611.      var
  612.        F : Text;
  613.        LFileInfo : Longint;
  614.        DFileInfo : DateTime; { declared in Dos unit }
  615.      begin
  616.        Assign( F, 'FSEARCH.PAS' );
  617.        Reset( F );
  618.        GetFTime ( F, LFileInfo );
  619.        UnpackTime ( LFileInfo, DFileInfo );
  620.        with DFileInfo do
  621.           Writeln(Month, '-', Day, '-', Year,
  622.             '  ',Hour:2,':',Min:2,':',Sec:2);
  623.  
  624.        { Change file's date to 1992 }
  625.        DFileInfo.Year := 1992;
  626.        PackTime ( DFileInfo, LFileInfo );
  627.        SetFTime ( F, LFileInfo );
  628.        Readln;
  629.       end.
  630.  
  631. Purpose:
  632.      PackTime converts a date and time record DT, containing individual values
  633. for Year, Month, Day, Hour, Min and Sec, into a 4 byte Longint reprsentation
  634. and returns the result in parameter variable Time.
  635.      PackTime is used with UnpackTime, for encoding and decoding the date and
  636. time data returned or set by GetFTime and SetFTime, respectively. You can write
  637. a program, such as the sample program above, to pre- or post-date files, as
  638. needed.  When that important project needs to be done on a Friday and you find
  639. yourself feverishly coding through late weekend hours, you still might be able
  640. to convince your boss that you really did finish the job on Friday!
  641. See GetFTime, SetFTime, UnpackTime
  642.  
  643.  
  644.  
  645. ParamCount function
  646. ----------------------------------------------------------------
  647. Declaration:  
  648.      function ParamCount : Word;
  649.  
  650. Purpose:
  651.      When you start up a program from the DOS command line, you can add a
  652. number of comand line parameters that are accessible from your program (see
  653. ParamStr).  ParamCount returns the total number of command line parameters
  654. entered on the command line.
  655.  
  656.  
  657.  
  658. ParamStr function
  659. ----------------------------------------------------------------
  660. Declaration:  
  661.      function ParamStr( Index: Word ) : String;
  662.  
  663. Purpose:
  664.      When you start up a program from the DOS command line, you can add a
  665. number of comand line parameters that are accessible from your program.   These
  666. command line parameters might be filenames, starting directories or any other
  667. values that your application requires.  For example, the command line compiler
  668. TPC has a large variety of command line options that may be specified when
  669. starting the compiler.  Inside your application, you can fetch each of the
  670. command line parameters by calling ParamStr and setting Index to choose a
  671. particular parameter.
  672.      Normally, you should restrict the value of Index to the range of 1 to
  673. ParamCount, where ParamCount returns the total number of command line
  674. parameters.  Invalid values for Index result in a null string being returned by
  675. ParamStr.  On DOS 3.0 and later, ParamStr(0) provides the name of the program
  676. that is currently executing.  ParamStr(0) is especially useful when an
  677. application must find the subdirectory from where it was launched.
  678. See ParamCount
  679.  
  680.  
  681.  
  682. Pi function
  683. ----------------------------------------------------------------
  684. Declaration:  function Pi : Real;
  685.  
  686. Purpose:
  687.      Pi returns the constant value 3.1415926535897932385, where the exact
  688. precision depends on the math emulation or math processor mode that is in use.
  689.  
  690.  
  691.  
  692. Port/PortW pseudo arrays
  693. ----------------------------------------------------------------
  694. Declaration:  
  695. When used for output:
  696.      Port[ Index ] := <byte valued expression>
  697.      PortW[ Index ] := <word valued expression>
  698.        
  699. When used for input:
  700.      <Result> := Port[ Index ];
  701.      <Result> := PortW[ Index ];
  702.  
  703. Example:
  704.      { Assign the value of Databyte to I/O address $3F8 }
  705.      Port[$3F8] := Databyte;
  706.  
  707. Purpose:
  708.      Port and PortW act like arrays whose index corresponds to a hardware I/O
  709. port.  The index value ranges from 0 up to 65,535.  By using Port for byte
  710. values and PortW for word values, these pseudo-array variables are used to
  711. write high level language implementations of hardware device drivers, such as
  712. serial port access routines. PortW is used to access a word value.
  713.      Port and PortW are not really arrays but Pascal level access mechanisms
  714. for the low-level data ports.  As such, Port and PortW should only be used to
  715. the left of an assignment statement or as a component in an expression.  They
  716. cannot be used as variable parameters to any procedure or function.
  717.  
  718.  
  719.  
  720. Pos function
  721. ----------------------------------------------------------------
  722. Declaration:  
  723.      function Pos ( Substr, S: String ): Byte;
  724.  
  725. Example:
  726.  
  727.      { This examples uses the Pos() function to implement
  728.        a string replacement routine }
  729.  
  730.      function Replace ( SearchFor, ReplaceWith, 
  731.             InThis : String ): String;
  732.      { Finds every occurrence of SearchFor within InThis, and
  733.      changes each occurrence to the value of ReplaceWith.
  734.      This function solves the problem recursively.  Once it finds
  735.      an occurrence of SearchFor, it makes the first replacement
  736.      and then calls itself on the remainder of the string.}
  737.      var
  738.        Index : Integer;
  739.      begin
  740.        Index := Pos (SearchFor, InThis);
  741.        if  Index > 0  then
  742.           Replace := Copy ( InThis, 1, 
  743.                  Pos(Searchfor, InThis) - 1) +
  744.                  ReplaceWith +
  745.                  Replace( SearchFor, ReplaceWith,
  746.                  Copy( InThis, Index + Length(Searchfor),255 ));
  747.        else
  748.           Replace := InThis;
  749.      end;
  750.  
  751. Example Usage of Replace:
  752.  
  753.      Writeln(
  754.      Replace('e', '*',
  755.         'The quick brown fox jumped over the lazy dog.');
  756.  
  757. outputs,
  758.  
  759.      Th* quick brown fox jump*d ov*r the lazy dog.
  760.  
  761. Purpose:
  762.      When you need to search for a substring within another string, use the Pos
  763. function.  Pos scans through string S searching for an occurrence of Substr. 
  764. Iffound, Pos returns the character index in S where Substr begins. If not
  765. found, Pos returns 0.
  766.      The example function Replace, above, is a handy routine to perform a "find
  767. and replace" operation on strings.  Replace uses Pos to find the first
  768. occurence of the Searchfor string, replaces it with ReplaceWith, and then calls
  769. Replace recursively to change the remainder of the string.
  770.  
  771.  
  772.  
  773. Pred function
  774. ----------------------------------------------------------------
  775. Declaration:  
  776.      function Pred( X ) : <same type as X>;
  777.  
  778. Example:
  779.      type
  780.        DaysOfTheWeek= (Sun,Mon,Tue,Wed,Thu,Fri,Sat);
  781.      var
  782.        Day : DaysOfTheWeek;
  783.      ...
  784.      Day := Tue;
  785.      Day := Pred( Day );      { Sets Day to Mon }
  786.  
  787. Purpose:
  788.      Pred(X) sets X to the predecessor value in the ordinal valued set from
  789. which X is derived.   In the case of an integer or word value, Pred is
  790. equivalent to the Dec function.  Some additional examples:
  791.      Pred(10) = 9
  792.      Pred('B') = 'A'
  793. See Dec, Inc, Succ
  794.  
  795.  
  796.  
  797. PrefixSeg variable
  798. ----------------------------------------------------------------
  799. Declaration:  
  800.      PrefixSeg: Word = 0;
  801.  
  802. Purpose:
  803.      PrefixSeg contains the segment address of the Program Segment Prefix
  804. (PSP).  The PSP contains information about the program loaded in memory,
  805. including the command line that was used to load the program (so the program
  806. can access command line parameters), pointers to the memory blocks used by the
  807. program and other information.  PrefixSeg is used in the example TSR program
  808. shown in Chapter 11 of this book.  For further details about the data contained
  809. in the PSP, consult Appendix F of DOS Programmer's Reference, 2nd edition, Que
  810. Books, 1989.  
  811.  
  812.  
  813.  
  814. Ptr function
  815. ----------------------------------------------------------------
  816. Declaration:  
  817.      function Ptr( Seg, Ofs : Word) : Pointer;
  818.  
  819. Example:
  820.      { Using Ptr to manufacture a pointer into the DOS data area
  821.      to obtain the number of Kbytes of low memory available to
  822.      DOS.  On most systems today, this will always 
  823.      be 640k bytes. }
  824.      var
  825.        DOSMemory : word;
  826.      begin
  827.        DOSMemory:= Word(Ptr( $40, 19 )^);
  828.        Writeln('Low DOS Memory, in k bytes=', DOSMemory);
  829.      end.
  830.  
  831. Purpose:
  832.      Ptr is used to create a pointer to a specific memory address, specified by
  833. Seg:Ofs.
  834.  
  835.  
  836.  
  837. Random function
  838. ----------------------------------------------------------------
  839. Declaration:  
  840.      function Random [ (Range: Word) ] : Word
  841. or
  842.      function Random [ (Range: Word) ] : Real;
  843.  
  844. Example:
  845.      { On an EGA or VGA monitor, randomly rearrange the colors in
  846.      the palette }
  847.      Randomize;
  848.      repeat
  849.        SetPalette( Random(GetMaxColors), Random(GetMaxColors));
  850.        Delay ( 50 );
  851.      until Keypressed;
  852.  
  853. Purpose:
  854.      Random produces a pseudo-random sequence of numbers.  In its default
  855. usage, Random returns a Real random value between 0 and 1 ( 0<= Random < 1). 
  856. Each subsequent call to Random returns another number in the pseudo-random
  857. sequence.
  858.      If you specify a Range value, Random returns a Word value betetween 0 up
  859. to Range ( 0<= Random < Range).  For instance, Random(10) returns random values
  860. in the range of 0 to 9.
  861.      The specific sequence generated by Random depends upon the initial value
  862. of the RandSeed variable, which is set by Randomize.  If you do not call
  863. Randomize at the start of your program, every time that your program executes
  864. it will generate the same random number sequence.
  865.  
  866.  
  867.  
  868. Randomize procedure
  869. ----------------------------------------------------------------
  870. Declaration:  
  871.      procedure Randomize;
  872.  
  873. Purpose:
  874.      Randomize sets the RandSeed variable to a value translated from the
  875. current system clock time.  Generally you will wish to call Randomize at the
  876. start of your program.  If you do not call Randomize, your program will
  877. generate the same random number sequence each time that it is executed.   You
  878. can select a specific random number sequence by initializing the RandSeed
  879. variable to a value of your own choosing.  See the description of RandSeed.
  880.  
  881.      
  882.  
  883. RandSeed variable
  884. ----------------------------------------------------------------
  885. Declaration:  
  886.      RandSeed : Longint;
  887.  
  888. Example:
  889.  
  890.      RandSeed := 99879;
  891.      repeat
  892.        SetPalette( Random(GetMaxColors), Random(GetMaxColors) );
  893.        Delay ( 50 );
  894.      until Keypressed;
  895.  
  896. Purpose:
  897.      RandSeed contains the random number generator seed value.  By explicitly
  898. setting RandSeed to a value of your choosing, you can repeatedly generate the
  899. same random number sequence.  
  900.  
  901.  
  902.  
  903. Read procedure
  904. ----------------------------------------------------------------
  905. Purpose:
  906.      The Read procedure inputs values from the keyboard or text file and
  907. assigns the values to variables.  When used on typed files, Read reads the next
  908. file component into a variable.
  909.      By setting {$I-}, you can manually check for errors that may occur when
  910. reading data by checking the result code from IOResult.
  911.  
  912. Text files
  913. Declaration:  
  914.      procedure Read( [var F: Text; ] V1 [, V2, ..., Vn ] );
  915.  
  916. Description:
  917.      When reading data from a text file or the system input (keyboard) file,
  918. the behavior of Read depends on the data type of the variables to receive the
  919. data and the position of the file pointer (for example, at end of file).  The
  920. basic operation is to copy data from the input, convert if necessary to the
  921. appropriate format, and place into one of the parameter variables.  Read may
  922. have from 1 to many variables specified, and the variable type may be different
  923. for each of the variables.  For example, to read 2 integers and a single real
  924. value, write:
  925.      var
  926.        N1, N2 : Integer;
  927.        X : Real;
  928.      ...
  929.      Read( N1, N2, X );
  930.  
  931. You should type the response to this input using blanks, tabs or the Enter key
  932. to separate each of the values, such as,
  933.      57 68 2345.987
  934. Interestingly, you may use the Enter key to separate each value, such as,
  935.      57 <Enter>
  936.      68 <Enter>
  937.      2345.987 <Enter>
  938.  
  939. Important!  The Dangling Enter key!
  940.      In the previous example, the last <Enter> remains in the input buffer. 
  941. Forthis reason, when reading input from the keyboard, it is recommended that
  942. you use the Readln procedure instead of Read.  Readln behaves identically to
  943. Read except that Readln swallows and disgards the Enter key.
  944.      From a user interface perspective, it would be preferable to allow numeric
  945. input values to be separated by the comma "," character.  Unfortunately, Readln
  946. does not support this capability.
  947.      The details of how Read performs on the various data types are described
  948. in the following sections.  Also see the closely related procedure, Readln, and
  949. the output procedures Write and Writeln.
  950.  
  951.  
  952. String
  953.      Read copies input characters to the string variable, until it encounters
  954. an end-of-line or end-of-file condition.  The end-of-line character is never
  955. included in the data copied to the string variable.  When reading data from a
  956. text file, the next Read operation begins at the previous end-of-line
  957. character.  Thinking that it is at the end of another line, Read returns a null
  958. string.  The result of this is that Read only reads the first line and then
  959. gets stuck on the end-of-line character.  The solution is to use Readln for
  960. reading successive lines of text.
  961.      If the input line exceeds the defined maximum length for the string
  962. variable, then only that portion of the text that will fit is read into the
  963. string variable.  The remaining text out to the next end-of-line character is
  964. disgarded.
  965.  
  966. Integer
  967.      When reading integer values to an integer variable, Read skips over
  968. leading blanks and tabs and then reads until encountering the next blank, tab,
  969. end-of-line character or end-of-file.  The characters that is has read are then
  970. converted to an integer value.  If these characters do not correspond to the
  971. proper format for an integer, an error condition occurs.  You can trap these
  972. errors by setting {$I-} and checking the value of IOResult.  
  973.      If the end-of-file is reached while reading the characters that make up an
  974. integer value, then the integer value is set to 0.
  975.  
  976. Real
  977.      When reading real number values to a real variable, Read skips over
  978. leading blanks and tabs and then reads characters until encountering the next
  979. blank, tab, end-of-line character or end-of-file.  The characters that it has
  980. read, assuming that they correspond to the proper format for a real constant
  981. are then converted to a real value and assigned to the variable.  If the
  982. characters have an invalid format for a real constant, then an error occurs.
  983.  
  984. Char
  985.      Read (Ch), where Ch is a Char data type, reads the next single character
  986. from the file and copies the character to Ch.  If the file is positioned at the
  987. end of file, Ch is set to Chr(26) to mark the end-of-file.  If the file pointer
  988. is positioned on an end-of-line character, then Ch is set to Chr(13).  Note
  989. that while you can use Read(Ch) to read an individual character from the
  990. standard input or keyboard, you must still press the Enter key to terminate the
  991. input.  If you wish to read invididual keystrokes without having to press
  992. Enter, use the ReadKey function.
  993.  
  994.  
  995. Typed files
  996. Declaration:  
  997.      procedure Read ( F, V1 [, V2, ..., Vn ] );
  998.  
  999. Description:
  1000.      In this form, Read is used to read individual recordor (or file
  1001. components) from a disk file.  You can read the data in the file sequentially,
  1002. by specifying multiple data values, or by repeatedly calling Read.  After each
  1003. record is read, the file pointer is advanced to the next record in the file. 
  1004. Toread records at random locations, call Seek to reposition the file pointer to
  1005. a new location in the file.  As with all I/O operations, you can manually check
  1006. for I/O errors by setting the {$I-} compiler option and checking the result
  1007. value returned by IOResult.
  1008.      For further information on record file operations, see chapter 3, "Disk
  1009. File operations".
  1010. See Seek, Write
  1011.  
  1012.  
  1013.  
  1014. ReadKey function
  1015. ----------------------------------------------------------------
  1016. Declaration:  
  1017.      function ReadKey : Char;
  1018.  
  1019. Unit:       Crt
  1020.  
  1021. Example:
  1022.  
  1023.    1  { KEYTEST.PAS }
  1024.    2  Program KeyTest;
  1025.    3  Uses
  1026.    4    Crt;
  1027.    5  Var
  1028.    6   Code : Integer;
  1029.    7  
  1030.    8  
  1031.    9  Function GetKey : Integer;
  1032.   10  { Pauses for input of a single keystroke from the keyboard and returns
  1033.   11    the ASCII value.  In the case where an Extended keyboard key is
  1034. pressed,
  1035.   12    GetKey returns the ScanCode + 256.  The Turbo Pascal ReadKey function
  1036.   13    is called to perform the keystroke input.  This routine returns a 0
  1037.   14    when an Extended key has been typed (e.g. left or right arrow) and we
  1038.   15    must read the next byte to determined the Scan code.
  1039.   16  }
  1040.   17  Var
  1041.   18    Ch : Char;
  1042.   19  Begin
  1043.   20    Ch := ReadKey;
  1044.   21    If Ord(Ch) <> 0 Then
  1045.   22      GetKey := Ord(Ch)   { Return normal ASCII value }
  1046.   23    Else
  1047.   24    Begin
  1048.   25      { Read the DOS Extended SCAN code that follows }
  1049.   26      GetKey := Ord(ReadKey) + 256;
  1050.   27    End;
  1051.   28  End;{GetKey}
  1052.   29  
  1053.   30  Begin
  1054.   31  Repeat
  1055.   32    Code := GetKey;
  1056.   33    Writeln(Code);
  1057.   34  Until Code = 27;
  1058.   35  End.
  1059.  
  1060. Purpose:
  1061.      If a key has already been entered, ReadKey returns the key that was typed.
  1062. Otherwise, ReadKey waits for a key to be pressed on the keyboard.  In both
  1063. cases, the key that is entered is not echoed to the screen.
  1064.      Normal characters having ASCII codes from 1 to 255 are returned by
  1065. ReadKey.  However, the IBM PC supports additional character codes in order to
  1066. recognize the function keys, Ins, Del, and so on.  When one of these extended
  1067. keyboard characters is typed at the keyboard, ReadKey returns Chr(0) and you
  1068. must then call ReadKey a second time to read the actual scan code.  The
  1069. function GetKey, shown in the example above, provides a simple routine to read
  1070. both normal and extended IBM keyboard values.
  1071.  
  1072.  
  1073.  
  1074. Readln procedure
  1075. ----------------------------------------------------------------
  1076. Declaration:  
  1077.      procedure Readln( [var F: Text; ] [V1 , V2, ..., Vn ] );
  1078.  
  1079. Purpose:
  1080.      Readln is identical to Read except that after reading the input data,
  1081. Readln causes the file pointer to advance to the start of the next line (just
  1082. after the previous end-of-line marker).
  1083.      Unlike Read, you can call Readln with no parameters and Readln disgards
  1084. all input characters up to the next end-of-line.  Readln, without parameters,
  1085. is often used to wait for the user to press the Enter key, like this:
  1086.      Write('Press Enter to continue.');
  1087.      Readln;
  1088.  
  1089.  
  1090.  
  1091. Release procedure
  1092. ----------------------------------------------------------------
  1093. Declaration:  
  1094.      procedure Release (var P: Pointer);
  1095.  
  1096. Purpose:
  1097.      Release resets the top of heap pointer to the value in P, which should
  1098. have been initialized previously with a call to Mark.  See "The Use of Mark and
  1099. Release Procedures" in Chapter 3, "The Turbo Pascal Language" of the Turbo
  1100. Pascal Reference.
  1101.  
  1102.  
  1103.  
  1104. Rename procedure
  1105. ----------------------------------------------------------------
  1106. Declaration:  
  1107.      procedure Rename(var F; Newname : String );
  1108.  
  1109. Example:
  1110.      var
  1111.        OldName: String;
  1112.        NewName: String;
  1113.        F: File;
  1114.      begin
  1115.        Write('Old filename: ');
  1116.        Readln( OldName );
  1117.        Write('New filename: ');
  1118.        Readln( NewName );
  1119.        Assign(F, OldName);
  1120.        Rename(F, NewName );
  1121.      end.
  1122.  
  1123. Purpose:
  1124.      With a filename assigned to file identifier F (using Assign), call Rename
  1125. to change the name of the file to Newname.  F must not be open.  Interestingly,
  1126. if NewName contains a directory name in addition to the filename, you can use
  1127. Rename to move a file from one directory to another directory, with or without
  1128. a name change.   Further, this move is nearly instantaneous, is handled
  1129. internally by DOS shifting its internal file directory around, not by actually
  1130. copying the entire file from one directory to another. For example, to move
  1131. MYFILE from the current subdirectory to the \TOOLS subdirectory, write,
  1132.      Assign( F, 'MYFILE' );
  1133.      Rename( F, '\TOOLS\MYFILE' );
  1134.  
  1135.  
  1136.  
  1137. Reset procedure
  1138. ----------------------------------------------------------------
  1139. Declaration:  
  1140.      procedure Reset (var F [: File; RecSize: Word] );
  1141.  
  1142. Example:
  1143.      See "Disk file operations" in Chapter 3, "The Turbo Pascal Language".
  1144.  
  1145. Purpose:
  1146.      Reset opens an existing file of any type for subsequent reading or writing
  1147. of data and positions the file pointer to the beginning of the file.  In the
  1148. case of text files, Reset sets the file to read-only; if you wish to write to a
  1149. text file, use either Append or Rewrite to open the file.  Prior to calling
  1150. Reset, you should assign a filename to the file identifier by calling Assign (a
  1151. null filename '' may be used to open the standard input file).
  1152.      The parameter RecSize may only be used with untyped files only and
  1153. specifies a record size to be used when reading or writing blocks of data.  If
  1154. unspecified, the default record size is 128 bytes.  See BlockRead/BlockWrite
  1155. for additional details on block I/O.
  1156.      If the file does not exist, Reset produces an I/O error that can be
  1157. trapped by setting the {$I-} compiler directive and manually checking the
  1158. IOResult return value.
  1159. See Append, Assign, Close, Rewrite, Truncate
  1160.  
  1161.  
  1162.  
  1163. Rewrite procedure
  1164. ----------------------------------------------------------------
  1165. Declaration:  
  1166.      procedure Rewrite (var F [: File; RecSize: Word] );
  1167.  
  1168. Example:
  1169.      See "Disk file operations" in Chapter 3, "The Turbo Pascal Language" of
  1170. The Turbo Pascal Reference.
  1171.  
  1172. Purpose:
  1173.      Rewrite creates a new file.  Prior to calling Rewrite, you should call
  1174. Assign to associate a filename (a null filename '' specifies the standard
  1175. output file) with the file identifier F.  Rewrite creates a new disk file,
  1176. erasing any previous file with the same name, and in the case of a text file,
  1177. makes the file available for write-only access.
  1178.      For untyped files, you can specify a record size parameter in RecSize (see
  1179. BlockRead/BlockWrite).  If unspecified, the default record size is 128 bytes.
  1180. See Append, Assign, Close, Reset, Truncate
  1181.  
  1182.  
  1183.  
  1184. RmDir procedure
  1185. ----------------------------------------------------------------
  1186. Declaration:  
  1187.      procedure RmDir ( S: String );
  1188.  
  1189. Purpose:
  1190.      Use RmDir to delete an existing - and empty of any files - subdirectory. 
  1191. Sspecifies the name of the directory to delete.  If the directory still
  1192. contains files, or if the directory does not exist, an I/O error occurs (use
  1193. the {$I-} compiler directive and IOResult to check for errors).
  1194. See MkDir
  1195.  
  1196.  
  1197.  
  1198. Round function
  1199. ----------------------------------------------------------------
  1200. Declaration:  
  1201.      procedure Round ( X: Real );
  1202.  
  1203. Example:
  1204.      {Round the value of Pi to the nearest's thousandth's place }
  1205.      Writeln( Round ( Pi * 1000 ) / 1000.0 );
  1206.  
  1207. Purpose:
  1208.      Where X is a real value, X is rounded to the nearest integer value.  When
  1209. X is halfway between two integer values (e.g. 3.5), then X is rounded as
  1210. follows:
  1211.        If X > 0, then X is rounded up to the next integer value.  Examples: 3.5
  1212.        becomes 4;  7.5 becomes 8.
  1213.        if X < 0, then X is rounded down to the next integer value.  Examples: 
  1214.        -3.5 becomes -4; -7.5 becomes 8.
  1215. The code shown in the example above illustrates a method of using Round to
  1216. round numbers to a particular number of decimal places.  In the example, the
  1217. value of Pi, 3.1415926535.... is multiple by 1000, producing 3141.5926535.... 
  1218. This value is then rounded to 3142.0, and divided by 1000.0, producing 3.142 as
  1219. the value of Pi rounded to the thousandth's place.
  1220. See Int, Trunc
  1221.  
  1222.  
  1223.  
  1224. RunError procedure
  1225. ----------------------------------------------------------------
  1226. Declaration:  
  1227.      procedure RunError [ ( ErrorCode: Byte ) ];
  1228.  
  1229. Example:
  1230.      
  1231.      {$IFDEF Validate}
  1232.      if (Temperature < 0.0) or (Temperature > 212.0)  then
  1233.        RunError( TempOutOfRange );
  1234.      {$ENDIF}
  1235.  
  1236. Purpose:
  1237.      RunError, like the Halt procedure, stops program execution.  RunError,
  1238. however, generates a run-time error by setting ErrorAddr equal to the address
  1239. of the statement that called RunError, and if specified, sets ExitCode to
  1240. ErrorCode.
  1241.      A good use for RunError is to assist in debugging your programs by placing
  1242. internal consistency checks into your code.  For example, inside your code, you
  1243. may wish to place special code to insure that values are always within their
  1244. specified range, that pointers are non-nil, and so on.  An invalid value
  1245. indicates that your program is not operating correctly, so you can call
  1246. RunError to force an immediate halt to program execution.  Normally, you should
  1247. place this type of check code inside of conditional compilation statements so
  1248. that you can remove it from the final version of your program.
  1249. See ErrorAddr, ExitCode, ExitProc, Halt
  1250.  
  1251.  
  1252.  
  1253. Seek procedure
  1254. ----------------------------------------------------------------
  1255. Declaration:  
  1256.      procedure Seek(var F; N: Longint);
  1257.  
  1258. Example:
  1259.      Also see "Random Access Data Files" in Chapter 3, "The Turbo Pascal
  1260. Language".
  1261.  
  1262.      type
  1263.        TDataRecord = record
  1264.           Name        : String[20];
  1265.           PhoneNumber : String[14];
  1266.           Age         : Integer;
  1267.           Available   : Boolean;
  1268.        end;
  1269.      var
  1270.        RandomFile  : File of TDataRecord;
  1271.        ...
  1272.      Write('Enter number of record to edit:  ');
  1273.      Readln( RecordNum );
  1274.      Seek( RandomFile, RecordNum );
  1275.      Read( RandomFile, DataRecord);
  1276.      if  DataRecord.Available  then
  1277.        Writeln('Record #', RecordNum, ' does not contain any data.');
  1278.  
  1279. Purpose:
  1280.      When performing random accesss to a disk file, Seek is used to position
  1281. the file pointer of file F, to the Nth component of the file.  Another way of
  1282. saying that is that Seek positions to the Nth record in the file.  The next
  1283. read or write operation will be made to record N.
  1284.      When you need to add new records to the end of a random access file, you
  1285. can use Seek to position to the last record, plus 1.  This way the next write
  1286. will append a new record to the end of the file.  A convenient way to access
  1287. the last record is to write,
  1288.      Seek ( F, FileSize(F) );
  1289. since FileSize returns the current filesize in terms of file components or
  1290. records.
  1291. See FilePos, FileSize, Read, Reset, Rewrite, Write
  1292.  
  1293.  
  1294.  
  1295. SeekEof function
  1296. ----------------------------------------------------------------
  1297. Declaration:  
  1298.      function SeekEof [  ( var F: Text ); ] 
  1299.  
  1300. Purpose:
  1301.      Text files often contain extra blanks, tabs or blank lines after the last
  1302. useful data contained in the file.  For this reason, its possible that the
  1303. Eof(F) function will return False, even though the next Read (F) will encounter
  1304. an end of file condition.  The solution is to call SeekEof instead of Eof. 
  1305. SeekEof skips ahead, past any blanks, tabs or blank lines to determine if the
  1306. current file pointer is at the logical end of file.
  1307.      Make sure that you use SeekEof only on open text files, and no other file
  1308. types.  To manually check for file errors, set the {$I-} compiler directive and
  1309. check IOResult.
  1310. See Eof
  1311.  
  1312.  
  1313.  
  1314. SeekEoln function
  1315. ----------------------------------------------------------------
  1316. Declaration:  function SeekEoln[ (var F: Text); ]
  1317. Purpose:
  1318.      SeekEoln exists for the same reason as SeekEof (See SeekEof).  SeekEoln
  1319. skips over trailing blanks and tabs in a line to locate the end-of-line marker.
  1320.  
  1321.  
  1322.  
  1323. Seg function
  1324. ----------------------------------------------------------------
  1325. Declaration:  
  1326.      function Seg(X): Word;
  1327.  
  1328. Purpose:
  1329.      Computes and returns the segment part of the segment:offset address of X,
  1330. where X is any identifier, including variables, procedures and functions.
  1331. See Addr, Ofs
  1332.  
  1333.  
  1334.  
  1335. SetCBreak procedure
  1336. ----------------------------------------------------------------
  1337. Declaration:  
  1338.      procedure SetCBreak( Break: Boolean);
  1339.  
  1340. Unit:       Dos
  1341.  
  1342. Purpose:
  1343.      The DOS operating system periodically checks for a the Ctrl-Break key
  1344. combination being pressed during program execution.  As you know, pressing
  1345. Ctrl-Break interrupts the flow of program execution.  However, the actual
  1346. processing of the Ctrl-Break key depends on the state of a DOS internal
  1347. variable.  GetCBreak returns the current state of this flag:  if set to True,
  1348. DOS checks for Ctrl-Break at every DOS system call; if False, DOS checks only
  1349. during input/output operations to the console (CON:), printer (LPT:) or
  1350. communications ports (COMx:).  
  1351.      You can set the state of the Ctrl-Break flag by calling SetCBreak and
  1352. setting Break to True, to enable checking at each DOS system call; or False to
  1353. restrict checking to input/output operations.
  1354. See CheckBreak, GetCBreak
  1355.  
  1356.  
  1357.  
  1358. SetDate procedure
  1359. ----------------------------------------------------------------
  1360. Declaration:  
  1361.      procedure SetDate( Year, Month, Day: Word );
  1362.  
  1363. Unit:       Dos
  1364.  
  1365. Purpose:
  1366.      Sets the DOS system date to the Year, Month and Day parameters, where Year
  1367. should be in the range 1980 to 2099, Month in the range 1 to 12, and Day in the
  1368. range 1 to 31.  SetDate does not return an error status; if the date values are
  1369. erroneous, the new date is not set.
  1370. See GetDate, GetTime, SetTime
  1371.  
  1372.  
  1373.  
  1374. SetFAttr procedure
  1375. ----------------------------------------------------------------
  1376. Declaration:  
  1377.      procedure SetFAttr (var F; Attr: Word );
  1378.  
  1379. Unit:       Dos
  1380.  
  1381. Example:
  1382. Assign(F, 'SCRATCH.DAT' );
  1383. GetFAttr( F, Attr );
  1384. SetFAttr( F, Attr or Hidden ); { Make the file a hidden file }
  1385.  
  1386. Purpose:
  1387.      Every file on the system has associated with it a set of file attributes. 
  1388. These attributes indicate if the file is read-only, hidden, or perhaps a
  1389. directory name.  You can obtain a file's attribute settings by calling
  1390. GetFAttr, where F is a file variable to which a filename has been assigned with
  1391. Assign (but should not be open).
  1392.      Using SetFAttr, you can change the file's attributes, as shown in the
  1393. example above.  The bit pattern used for attributes is determined by these
  1394. constants:  
  1395.      ReadOnly    =  $01;
  1396.      Hidden   =  $02;
  1397.      SysFile     =  $04;
  1398.      VolumeID =  $08;
  1399.      Directory      = $10;
  1400.      Archive     =  $20;
  1401.      AnyFile     = $3F;
  1402. AnyFile is typically used with FindFirst and FindNext and doesn't really have
  1403. any use here except that it can be used to match any file attributes with an
  1404. and operation.  
  1405.      Combinations of attributes are set by or'ing the values together, as shown
  1406. in the example above.  To get and set the file's access date and time, see
  1407. GetFTime and SetFTime.
  1408.  
  1409.      
  1410.  
  1411. SetFTime procedure
  1412. ----------------------------------------------------------------
  1413. Declaration:  
  1414.      procedure SetFTime( var F; Time: Longint );
  1415.  
  1416. Unit:       Dos
  1417.  
  1418. Example:
  1419.  
  1420.      Assign( F, 'FSEARCH.PAS' );
  1421.      Reset( F );
  1422.      GetFTime ( F, LFileInfo );
  1423.      UnpackTime ( LFileInfo, DFileInfo );
  1424.      with DFileInfo do
  1425.        Writeln(Month, '-', Day, '-', Year,
  1426.           '  ',Hour:2,':',Min:2,':',Sec:2);
  1427.  
  1428.      { Change file's date to 1992 }
  1429.      DFileInfo.Year := 1992;
  1430.      PackTime ( DFileInfo, LFileInfo );
  1431.      SetFTime ( F, LFileInfo );
  1432.  
  1433. Purpose:
  1434.      Every file has associated with it, a date and time stamp indicating when
  1435. the file was last written to.  You can fetch this date and time information by
  1436. calling GetFTime (see GetFTime).  GetFTime returns the date and file time
  1437. packed into a Longint value (see UnpackTime for converting the packed time
  1438. format into individual date and time components).
  1439.      The example, above, shows how to use SetFDate to output a new date and
  1440. time stamp to the open file associated with F.  DFileInfo is declared as a DT
  1441. record, where DT defines the fields, Month, Day, Year, Hour, Min, Sec.  After
  1442. setting the field values, you must use PackTime to convert the record into a
  1443. packed Loingint, prior to calling SetFDate.
  1444. See GetFAttr, GetFTime, PackTime, SetFAttr, UnpackTime
  1445.  
  1446.  
  1447.  
  1448. SetIntVec procedure
  1449. ----------------------------------------------------------------
  1450. Declaration:  
  1451.      procedure SetIntVec( IntNo: Byte; Vector: Pointer);
  1452.  
  1453. Purpose:
  1454.      Places an address, Vector, in to the interrupt vector table at entry
  1455. number IntNo, where IntNo is a value from 0 to 255.
  1456. See GetIntVec
  1457.  
  1458.  
  1459.  
  1460. SetTextBuf procedure
  1461. ----------------------------------------------------------------
  1462. Declaration:  
  1463.      procedure SetTextBuf(var F: Text; var Buf [; Size: Word ] );
  1464.  
  1465. Example:
  1466.      (See GetMem for an example of a dynamically allocated text buffer).
  1467.  
  1468.      Program SetTextBufDemo;
  1469.      var
  1470.        F : Text;
  1471.        Buffer : Array[0..1023] of Char;
  1472.        TextLine : String;
  1473.  
  1474.      begin
  1475.        Assign( F, 'TEMP.PAS' );
  1476.        SetTextBuf( F, Buffer );
  1477.        Reset( F );
  1478.  
  1479.        while not Eof(F) do
  1480.        begin
  1481.           Readln( F, TextLine );
  1482.           Writeln( TextLine );
  1483.        end;
  1484.  
  1485.        Close( F );
  1486.      end.
  1487.  
  1488. Purpose:
  1489.      By default, all text files use an internal 128-byte buffer for reading and
  1490. writing textual data to and from the disk.  For faster text file performance,
  1491. programs can create their own text file buffer, of any appropriate size, by
  1492. calling SetTextBuf and passing the name of the buffer as the Buf variable
  1493. parameter.  By creating a larger text file buffer, such as 1,024 bytes, you
  1494. will generally see a significant improvement in performance.  You don't need to
  1495. specify the Size parameter; by default, SetTextBuf sets the internal text
  1496. buffer size to SizeOf(Buf).  The new  buffer will be used until you close file
  1497. F, or open a new file using the F file id.  After closing the file, be certain
  1498. to properly dispose of the buffer, particularly if the buffer is a dynamic
  1499. variable.
  1500.  
  1501. Important!  Call SetTextBuf Before Calling Append, Reset, or Rewrite
  1502.      As a rule of thumb, always call SetTextBuf just prior to calling Append,
  1503. Reset or Rewrite.  While you can call SetTextBuf after opening a file, the act
  1504. of switching text buffers can cause a potential loss of data.  So just don't do
  1505. that!
  1506. See "Disk file operations" in Chapter 3, or Append, Reset, Rewrite
  1507.  
  1508.  
  1509.  
  1510. SetTime procedure
  1511. ----------------------------------------------------------------
  1512. Declaration:  
  1513.      procedure SetTime(Hour, Minute, Second, Sec100: Word);
  1514.  
  1515. Unit:       Dos
  1516.  
  1517. Purpose:
  1518.      Use SetTime to set the system clock.  If any of the values are out of the
  1519. permissible ranges (0 to 23 for Hour, 0 to 59 for Minute and Second, and 0 to
  1520. 100 for Sec100), the time is not changed.
  1521. See GetTime
  1522.  
  1523.  
  1524.  
  1525. SetVerify procedure
  1526. ----------------------------------------------------------------
  1527. Declaration:  
  1528.      procedure SetVerify(Verify: Boolean);
  1529.  
  1530. Unit:       Dos
  1531.  
  1532. Purpose:
  1533.      By calling SetVerify with Verify set to True, DOS will subsequently verify
  1534. the accuracy of all disk write operations (by rereading the data it just
  1535. wrote).  Since this is a time consuming operation, many applications will
  1536. choose not to use this feature.  To turn off automatic verification, call
  1537. SetVerify with Verify to False.
  1538.  
  1539.  
  1540.  
  1541. Sin function
  1542. ----------------------------------------------------------------
  1543. Declaration:  
  1544.      function Sin ( X: Real ) : Real;
  1545.  
  1546. Example:
  1547.  
  1548.      GetAspectRatio ( Xasp, Yasp );
  1549.      { Compute (X,Y) 10% further out than the radius. }
  1550.      X := Round( 1.1 * Radius * Cos ( AngleInRadians ) );
  1551.      Y := - Round( 1.1 * Radius * Sin ( AngleInRadians ) *
  1552.             (Xasp/Yasp));
  1553.  
  1554. Purpose:
  1555.      Computes and returns the sine of X, where X is an angle measurement in
  1556. radians.  Note that many of the graphics routines use an angle measurement in
  1557. degrees. To convert from degrees to radians, divide the degree measurement by
  1558. 180 / Pi.
  1559. See ArcCos/ArcSin, ArcTan, Cos, Tan
  1560.  
  1561.  
  1562.  
  1563. SizeOf function
  1564. ----------------------------------------------------------------
  1565. Declaration:  
  1566.      function SizeOf( X ) : Word;
  1567.  
  1568. Purpose:
  1569.      SizeOf computes and returns the total memory storage, in bytes, of its
  1570. parameter X, where X is either a variable or a data type.  SizeOf is frequently
  1571. used when allocating memory blocks dynamically (such as GetMem ( PBuffer,
  1572. SizeOf(Buffer) )) and elsewhere.
  1573.  
  1574.  
  1575.  
  1576. Sound procedure
  1577. ----------------------------------------------------------------
  1578. Declaration:  
  1579.      procedure Sound(Hz : Word);
  1580.  
  1581. Unit:       Crt
  1582.  
  1583. Purpose:
  1584.      Activates the PC's speaker, setting it to a tone having the frequency (in
  1585. hertz or cycles per second) specified by Hz.  The only way to turn off the
  1586. speaker, once activated, is to call NoSound.  Between calls to Sound and
  1587. NoSound, use the Delay procedure to leave the speaker turned on for a set
  1588. amount of time.
  1589. See Delay, Sound
  1590.  
  1591.  
  1592.  
  1593. SPtr function
  1594. ----------------------------------------------------------------
  1595. Declaration:  
  1596.      function SPtr : Word;
  1597.  
  1598. Purpose:
  1599.      Returns the value of 80x86 SP (stack pointer) register.  SP is always
  1600. relative to the SS (Stack segment) register.
  1601. See SSeg
  1602.  
  1603.  
  1604.  
  1605. Sqr function
  1606. ----------------------------------------------------------------
  1607. Declaration:  
  1608.      function Sqr( X ) : <type of X>
  1609.  
  1610. Purpose:
  1611.      Returns X squared, which is equivalent to X * X.
  1612.  
  1613.  
  1614.  
  1615. Sqrt function
  1616. ----------------------------------------------------------------
  1617. Declaration:  
  1618.      function Sqrt(X: Real) : Real;
  1619.  
  1620. Purpose:
  1621.      Where X is greater than or equal to 0, Sqrt(X) returns the square root of
  1622. X.  Sqrt(X) if not defined for negatives values of X.
  1623.  
  1624.  
  1625.  
  1626. SSeg function
  1627. ----------------------------------------------------------------
  1628. Declaration:  
  1629.      function SSeg: Word;
  1630.  
  1631. Purpose:
  1632.      Returns the current value of the SS or Stack Segment register of the CPU.
  1633. See SPtr
  1634.  
  1635.  
  1636.  
  1637. Str procedure
  1638. ----------------------------------------------------------------
  1639. Declaration:  
  1640.      procedure Str(X [: Width [:Decimals] ]; var S: String);
  1641.  
  1642. Purpose:
  1643.      When you need to convert a byte, integer, word, longint, or one of the
  1644. real data types to a string representation, use the Str procedure, specifying
  1645. an optional field Width and number of Decimals of accuracy.  For example,
  1646.      Str( 3.14159, S );
  1647. sets S equal to '3.1415900000E+00'.  To convert the value to a decimal
  1648. notation, you must specify the Width and Decimals parameters, where Width
  1649. specifies the overall length of the resulting string, and Decimals specifies
  1650. the number of decimal places to be included in the result.  For example,
  1651.      Str( 3.14159:5:2, S );
  1652. sets S equal to '3.14'.  Changing Decimals from 2 to 4 sets S equal to
  1653. '3.1416'.  Note:  The value of X is rounded, as needed, to fit within the
  1654. specified width and decimal places.
  1655.      To convert the string representation of a number, say '3.14159' to the
  1656. internal numeric format, use the Val procedure.
  1657.  
  1658.  
  1659.  
  1660. Succ function
  1661. ----------------------------------------------------------------
  1662. Declaration:  
  1663.      function Succ(X) : <same type as X>;
  1664.  
  1665. Purpose:
  1666.      Where X is any ordinal value, Succ(X) returns the successor of X.  For
  1667. example, the Succ(9) is 10.  See Pred for an example involving ordinal types.
  1668. See Inc, Pred
  1669.  
  1670.  
  1671.  
  1672. Swap function
  1673. ----------------------------------------------------------------
  1674. Declaration:  
  1675.      function Swap(X) : <same type as X>;
  1676.  
  1677. Purpose:
  1678.      When X is either an integer or word value, Swap(X) returns the result of
  1679. swapping the high and low order bytes of X.  You can examine the high or low
  1680. order bytes of an integer or word value using the Hi and Lo functions.
  1681.  
  1682.  
  1683.  
  1684. SwapVectors procedure
  1685. ----------------------------------------------------------------
  1686. Declaration:  
  1687.      procedure SwapVectors;
  1688.  
  1689. Unit:       Dos
  1690.  
  1691. Example:
  1692.      See Exec.
  1693.  
  1694. Purpose:
  1695.      SwapVectors is normally used before and after calling the Exec procedure,
  1696. which is used to launch another application.  Essentially, SwapVectors results
  1697. in saving the state of the interrupt vectors before a call to Exec, and
  1698. restoring the vector table upon return.  This helps prevent problems that may
  1699. occur if your application depends on specific settings in the interrupt vector
  1700. table - settings that may be changed by the application which is launched.
  1701.  
  1702.  
  1703.  
  1704. Test8087 variable
  1705. ----------------------------------------------------------------
  1706. Declaration:  
  1707.      Test8087: Byte = 0;
  1708.  
  1709. Purpose:
  1710.      When a Turbo Pascal program starts up, the initialization code determines
  1711. if the 8087 math coprocessor is available for use, and sets Test8087 as
  1712. follows:
  1713.  
  1714. Value  Meaning
  1715. 0      No math coprocessor found.
  1716. 1      8087 available.
  1717. 2      80287 available.
  1718. 3      80387 available.
  1719.  
  1720.  
  1721.  
  1722. TextAttr variable
  1723. ----------------------------------------------------------------
  1724. Declaration:  
  1725.      TextAttr: Byte;
  1726.  
  1727. Unit:       Crt
  1728.  
  1729. Example:
  1730.      uses Crt;
  1731.      begin
  1732.        TextColor(3);
  1733.        TextBackground(5);
  1734.        Writeln('Foreground color=', TextAttr and 15);
  1735.        Writeln('Background color=', (TextAttr shr 4) and 15);
  1736.        Readln;
  1737.      end.
  1738.  
  1739. Purpose:
  1740.      Stores the currently defined text attributes (color, background color) in
  1741. internal format.
  1742.  
  1743.  
  1744.  
  1745. TextBackground procedure
  1746. ----------------------------------------------------------------
  1747. Declaration:  
  1748.      procedure TextBackground( Color: Byte );
  1749.  
  1750. Unit:       Crt
  1751.  
  1752. Purpose:
  1753.      Text written to the display has two color attributes:  a foreground color
  1754. and a background color.  TextBackground sets the current background color
  1755. attribute to the value of Color, such that all text output following the call
  1756. to TextBackground will be drawn with the specified background color.  Color
  1757. should have a value from 0 to 7, to choose one of the 8 possible background
  1758. colors.  You may substitute one of the following constants for your color
  1759. choice:
  1760.      Black       0
  1761.      Blue     1
  1762.      Green       2
  1763.      Cyan     3
  1764.      Red      4
  1765.      Magenta     5
  1766.      Brown       6
  1767.      LightGray      7
  1768.  
  1769.  
  1770.  
  1771. TextColor procedure
  1772. ----------------------------------------------------------------
  1773. Declaration:  
  1774.      procedure TextColor(Color: Byte);
  1775.  
  1776. Unit:       Crt
  1777.  
  1778. Purpose:
  1779.      Text written to the display has two color attributes, a foreground color
  1780. and a background color.  TextColor sets the foreground color attribute to the
  1781. value of Color, so that all subsequent text output will be written in the
  1782. selected color, using the current TextBackground color.  Foreground color
  1783. choices may range from 0 to 15, with values 8 through 15 referred to as "high
  1784. intensity" equivalents of colors 0 to 7.  You may use the following constants
  1785. to select the color choice:
  1786.      
  1787.      Black       0
  1788.      Blue        1
  1789.      Green       2
  1790.      Cyan        3
  1791.      Red         4
  1792.      Magenta     5
  1793.      Brown       6
  1794.      LightGray   7
  1795.      DarkGray    8
  1796.      LightBlue   9
  1797.      LightGreen  10
  1798.      LightCyan   11
  1799.      LightRed    12
  1800.      LightMagenta   13
  1801.      Yellow      14
  1802.      White       15
  1803.  
  1804.  
  1805.  
  1806. TextMode procedure
  1807. ----------------------------------------------------------------
  1808. Declaration:  
  1809.      procedure TextMode(Mode: Word);
  1810.  
  1811. Unit:       Crt
  1812.  
  1813. Example:
  1814.      TextMode ( CO80 );
  1815.  
  1816. Purpose:
  1817.      Most of today's video displays support a variety of text operating modes,
  1818. including both 40 and 80 column wide displays, color and black & white display
  1819. modes, and for EGA and VGA displays, the ability to display 43 or 50 lines of
  1820. text.  The TextMode procedure selects the appropriate display mode by setting
  1821. Mode to one of the following constants:
  1822.  
  1823.      BW40        Selects B&W in 40 x 25 line display mode
  1824.      BW80        Selects B&W in 80 x25  line display mode
  1825.      Mono        Selects B&W in 80 x25 line on monochrome
  1826.                  display adaptor card
  1827.      CO40        Selects color in 40 x 25 line display mode
  1828.      CO80        Selects color in 80 x 25 line display mode
  1829.      C40         Same as CO40
  1830.      C80         Same as CO80
  1831.      LastMode    Restores the previous video mode prior to
  1832.                  program startup.
  1833.  
  1834. The selected text mode takes effect immediately and results in the screen being
  1835. cleared.
  1836.      LastMode is a variable and it stores the contents of the video mode at the
  1837. time the program was started.  If your program changes video modes during
  1838. program execution, you may wish to save the value of LastMode so that you can
  1839. restore the appropriate video mode at program termination (also see ExitProc).
  1840.      You may also use TextMode to select 43 or 50 line mode for use on EGA/VGA
  1841. displays by adding or or'ing the constant Font8x8 (where Font8x8 = 256 and
  1842. selects a small font for use in the higher resolution modes) to the mode
  1843. selection constant, like this:
  1844.      TextMode( LastMode and 255  or Font8x8 );
  1845. In this form, the current video mode (such as 80 column color) is retained but
  1846. the number of lines is increased to 43 or 50 lines, depending on your display. 
  1847. You may explicitly select both a video mode and 43 or 50 line mode by writing:
  1848.      TextMode( CO80 + Font8x8 );
  1849. To switch back to 25 line mode and maintain the the other mode settings, you
  1850. can write,
  1851.      TextMode( LastMode and 255 );
  1852. or specifically set a new mode, such as,
  1853.      TextMode( BW80 );
  1854. You can also use the Lo() and Hi() functions to check the value of LastMode. 
  1855. Hi(LastMode) returns Font8x8 if 43/50 line mode is in effect.  Lo(LastMode)
  1856. returns the current video mode.
  1857.  
  1858.  
  1859.  
  1860. Trunc function
  1861. ----------------------------------------------------------------
  1862. Declaration:  
  1863.      function Trunc( X: Real ): Longint;
  1864.  
  1865. Purpose:
  1866.      Trunc converts the real value X to a longint integer value by disgarding
  1867. the fractional portion of X.  For example, Trunc(3.14159) results in 3.  When
  1868. converting real values to Longint, be aware that the range of valid real
  1869. numbers exceeds the permissible range of Longint, and it is possible to receive
  1870. an out of range run-time error.
  1871. See Frac, Int, Round
  1872.  
  1873.  
  1874.  
  1875. Truncate procedure
  1876. ----------------------------------------------------------------
  1877. Declaration:  
  1878.      procedure Truncate(var F);
  1879.  
  1880. Purpose:
  1881.      When using any open file, other than text files, Truncate(F) disgards all
  1882. current data in the file from the current file pointer position on to the end
  1883. of the file, effectively making the current file position the new end of file.
  1884.  
  1885.  
  1886.  
  1887. Unpacktime procedure
  1888. ----------------------------------------------------------------
  1889. Declaration:  
  1890.      procedure UnpackTime(Time: Longint; var DT: DateTime);
  1891.  
  1892. Unit:       Dos
  1893.  
  1894. Example:
  1895.      uses dos;
  1896.      var
  1897.        F : Text;
  1898.        LFileInfo : Longint;
  1899.        DFileInfo : DateTime; { declared in Dos unit }
  1900.      begin
  1901.        Assign( F, 'FSEARCH.PAS' );
  1902.        Reset( F );
  1903.        GetFTime ( F, LFileInfo );
  1904.        UnpackTime ( LFileInfo, DFileInfo );
  1905.        with DFileInfo do
  1906.           Writeln(Month, '-', Day, '-', Year,
  1907.             '  ',Hour:2,':',Min:2,':',Sec:2);
  1908.        Readln;
  1909.      end.
  1910.  
  1911. Purpose:
  1912.      The procedures GetFTime, SetFTime, FindFirst and FindNext all use a
  1913. special packed date/time format that packs the date and time information into a
  1914. Longint value.  To convert the Longint packed representation into individual
  1915. date and time components, use UnPackTime.  To convert back to packed format,
  1916. use PackTime.
  1917.      UnPackTime converts its Time parameter value into the contents of the DT
  1918. record parameter variable.  DT contains separate fields for Year, Month, Day,
  1919. Hour, Min and Sec, each a Word type value.  You can use these fields to display
  1920. the date or time of a file in traditional date or time formats.
  1921.  
  1922.  
  1923.  
  1924. UpCase function
  1925. ----------------------------------------------------------------
  1926. Declaration:  
  1927.      function UpCase (Ch: Char): Char;
  1928.  
  1929. Example:
  1930.      function Uppercase( S : String ): String;
  1931.      var
  1932.        I : Integer;
  1933.      begin
  1934.        for I := 1 to Length(S) do
  1935.           S[I] := Upcase(S[I]);
  1936.        Uppercase := S;
  1937.      end;
  1938.  
  1939.      begin
  1940.  
  1941.        Writeln(Uppercase('Now is the time for all good men and women...'));
  1942.        Readln;
  1943.  
  1944.      end.
  1945.  
  1946. Purpose:
  1947.      UpCase converts its parameter Ch to uppercase, (if Ch is a letter from 'a'
  1948. to 'z') or makes no changes if Ch is not a lower case letter, and returns the
  1949. new value as its return result.  The example above shows a simple function to
  1950. convert an entire string to upper case.
  1951.  
  1952.  
  1953.  
  1954. Val procedure
  1955. ----------------------------------------------------------------
  1956. Declaration:  
  1957.      procedure Val(S: String; var V; var Code: Integer);
  1958.  
  1959. Example:
  1960.      uses Crt;
  1961.      var
  1962.        S : String;
  1963.        Result : Real;
  1964.        ErrCode : Integer;
  1965.      begin
  1966.        ClrScr;
  1967.        Gotoxy(1,10);
  1968.        Write('Enter number: ');
  1969.        Readln(S);
  1970.        {$R-}
  1971.        Val( S, Result, ErrCode );
  1972.        if ErrCode = 0 then
  1973.           Writeln(S, ' converted successfully to ', Result )
  1974.        else
  1975.        begin
  1976.           Gotoxy( 14+ErrCode, 11 );
  1977.           Write('^ invalid character in number.');
  1978.        end;
  1979.        Readln;
  1980.      end.
  1981.  
  1982. Purpose:
  1983.      Val converts a string containing a number, into its internal numeric
  1984. format for the appropriate variable type, such as integer or real.  The string
  1985. to convert is passed as parameter S and is returned in variable parameter V. 
  1986.      The string to convert must contain a valid number for the type of the
  1987. variable parameter V.  If an invalid character is detected during the
  1988. conversion, Code is set to the index of the offending character within string
  1989. S.  The example code above uses the returned error code to display a pointer to
  1990. the invalid character.
  1991.      When converting numbers, its possible for the number in S to be out of
  1992. range of the permissible values for variable V.  For example, attempting to
  1993. convert the string value shown below results in a range violation:
  1994.      var
  1995.        W : Word;
  1996.      ...
  1997.      Val('8799343.5', W, ErrCode );
  1998.  
  1999. To avoid out of range errors, you can select the {$R-} compiler directive to
  2000. disable automatic range checking.  A more thorough procedure, however, is to
  2001. convert the value first to a temporary Real or Longint variable and then use an
  2002. if-then statement to insure that the result falls within the valid range for
  2003. the target variable.
  2004.      
  2005.  
  2006.  
  2007. WhereX function
  2008. ----------------------------------------------------------------
  2009. Declaration:  
  2010.      function WhereX : Byte;
  2011.  
  2012. Unit:       Crt
  2013.  
  2014. Purpose:
  2015.      Returns the current X coordinate of the text cursor.  WhereY returns the
  2016. corresponding Y coordinate.
  2017.  
  2018.  
  2019.  
  2020. WhereY function
  2021. ----------------------------------------------------------------
  2022. Declaration:  
  2023.      function WhereY: Byte;
  2024.  
  2025. Unit:       Crt
  2026.  
  2027. Purpose:
  2028.      Returns the current Y coordinate of the text cursor.  
  2029.  
  2030.  
  2031.  
  2032. WindMin/WindMax variables
  2033. ----------------------------------------------------------------
  2034. Declaration:  
  2035.      WindMin, WindMax : Word;
  2036.  
  2037. Unit:       Crt
  2038.  
  2039. Purpose:
  2040.      WindMin stores the coordinate of the upper left corner and WindMax the
  2041. lower right corner of a window defined by the Window procedure.  The values are
  2042. stored such that the X value is stored in the low byte and Y in the high byte. 
  2043. Note that in WindMin and WindMax, the stored values are 0-relative, and not
  2044. 1-relative as used in the Window procedure.  This means that, for example,
  2045. WindMax may contain an X value of 24 (instead of 25) and a Y value of 79
  2046. (instead of 80).
  2047.  
  2048.  
  2049.  
  2050. Window procedure
  2051. ----------------------------------------------------------------
  2052. Declaration:  
  2053.      procedure Window(X1, Y1, X2, Y2: Byte);
  2054.  
  2055. Unit:       Crt
  2056.  
  2057. Purpose:
  2058.      When your program starts running, the default text window is the entire
  2059. screen, from (1,1) to (80,25).  However, you can redefine this text window to a
  2060. smaller region of the screen, and thereafter, all subsequent output and related
  2061. screen I/O statements are performed relative to the location of the window. 
  2062. Theparameters (X1,Y1) define the upper left corner of the window, and (X2,Y2)
  2063. define the lower right corner of the window.  For example, to define a narrow
  2064. window occupying just the right half of the screen, you may write,
  2065.      Window(40, 1, 80, 25 );
  2066. After the call to Window, subsequent I/O will be relative to this window.  A
  2067. Gotoxy(10,10) positions the cursor to the physical location (40+10, 1+10).
  2068.      You can use the Window statement for a variety of purposes because it
  2069. effects all of the following routines:
  2070.      ClrEol, ClrScr, DelLine, GotoXY, InsLine, WhereX, WhereY, Read, Readln,
  2071. Write, Writeln
  2072.      You can, for instance, create a small viewing window on the screen for
  2073. storing a list of items.  Through the use of the DelLine and InsLine
  2074. procedures, you can make text within the viewing window scroll up or down, as
  2075. required.
  2076. Important!  Window Doesn't do Windows!
  2077.      Window does not provide for overlapping windows nor does it save the
  2078. region behind the active window.  Window merely provides a simple way of
  2079. restricting your screen output to specific regions on the screen.
  2080. See WindMin/WindMax
  2081.  
  2082.  
  2083.  
  2084. Write procedure
  2085. ----------------------------------------------------------------
  2086. Purpose:
  2087.      When used with text output files, Write outputs one or more values to the
  2088. screen or to a text file.  When used with typed files, Write outputs its
  2089. parameter values to the next file component (or record) in the file.  For typed
  2090. files only, Seek may be used to position the file pointer to specific record
  2091. location prior to calling Write.
  2092.  
  2093. Write with Text Files
  2094. Declaration:  
  2095.      procedure Write( [ var F: Text; ] V1 [, V2, ..., Vn ] );
  2096.  
  2097. Description:
  2098.      Write outputs its parameters to the screen or to the text file F, if F is
  2099. specified.  For numeric parameters, a MinWidth and a DecPlaces parameter may
  2100. specify the minimum character width allocated to the item, and a number of
  2101. decimal places, respectively, using the format:
  2102.      Write( V1: MinWidth : DecPlaces );
  2103. MinWidth and DecPlaces are optional, however MinWidth must be specified in
  2104. order to specify DecPlaces, and DecPlaces may only be specified for real data
  2105. types.  If the length of the item being output is less than the MinWidth
  2106. specified, then leading blanks are placed before the item so that it will
  2107. occupy at least MinWidth characters.  For example,
  2108.      Write('/', '*' : 5, '/');
  2109. displays,
  2110.      /     */
  2111.  
  2112. Formatting Trick
  2113.      Many applications need to output large groups of blanks between output
  2114. items, such as when formatting a table of values.  While there are several ways
  2115. to accomplish this, such as placing Write(' ') inside a for loop, the easiest
  2116. method uses the MinWidth parameter to specify the number of blanks desired,
  2117. like this, which outputs 40 blanks:
  2118.      Write(' ':40);
  2119.  
  2120. Output formatting for each data type is described in the following sections.
  2121.  
  2122. String
  2123.      String values are copied directly to the output, byte by byte.  If
  2124. MinWidth is specified, sufficient leading blanks are output, if needed, to make
  2125. the string occupy exactly MinWidth character spaces.  If the string length
  2126. exceeds MinWidth, then the entire string is output.
  2127.  
  2128. Integer, Word, Longint
  2129.      Integer values are converted from their internal format to a textual
  2130. representation.  If MinWidth is specified, sufficient leading blanks are
  2131. output, if needed, to make the textual representation of the integer as wide as
  2132. MinWidth.
  2133.  
  2134. Real
  2135.      Real values are normally output in exponential notation, such that the
  2136. statement,
  2137.      Writeln(Pi)
  2138. outputs,
  2139.      3.1415926536E+00
  2140. When MinWidth is not specified for a real value, a default MinWidth of 17 is
  2141. assumed.  In the exponential floating point format, if MinWidth is less than 8,
  2142. MinWidth is set to 8.  To output a real value in familiar fixed point notation,
  2143. such as,
  2144.      3.1416
  2145. you must specify a MinWidth and DecPlaces parameter.  For example,
  2146.      Writeln(Pi:7:4);
  2147. outputs,
  2148.      3.1416
  2149. Note that this may resulting in rounding of the value, as needed.
  2150.  
  2151. Char
  2152.      Individual character values are output directly.  If MinWidth is
  2153. specified, the MinWidth-1 leading blanks are placed before the character value.
  2154.  
  2155. Boolean
  2156.      Boolean values are displayed as either True or False, according to the
  2157. value of the boolean expression.
  2158.  
  2159.  
  2160. Write with Typed Files
  2161. Declaration:  
  2162.      procedure Write( var F; V1, [, V2, ..., Nn ] );
  2163.  
  2164. Description:
  2165.      When used with typed files, Write outputs one or more components to the
  2166. file, and positions the file pointer to the next record in the file.  The Seek
  2167. procedure may be used to position the file pointer prior to writing the record.
  2168. See  "Disk file operations" in Chapter 3, "The Turbo Pascal Language" for
  2169. complete details on sequential and random typed file access.
  2170.  
  2171.  
  2172.  
  2173. Writeln procedure
  2174. ----------------------------------------------------------------
  2175. Declaration:  
  2176.      procedure Writeln( [var F:Text; ] [V1 [V2, ..., Vn] ] );
  2177.  
  2178. Purpose:
  2179.      For use in displaying output to the screen or writing output to text
  2180. files, Writeln is equivalent to Write, except that it also outputs an
  2181. end-of-line character following the parameters.
  2182.  
  2183.